;;; This file is part of guix-bavier.git
;;; Copyright © 2019 Eric Bavier <bavier@member.fsf.org>
;;; License: GPLv3+

(define-module (bavier packages rpm)
  #:use-module (guix packages)
  #:use-module (guix build-system python)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module (gnu packages aspell)
  #:use-module (gnu packages check)
  #:use-module (gnu packages cpio)
  #:use-module (gnu packages enchant)
  #:use-module (gnu packages freedesktop)
  #:use-module (gnu packages glib)
  #:use-module (gnu packages perl)
  #:use-module (gnu packages python)
  #:use-module (gnu packages python-check)
  #:use-module (gnu packages python-xyz)
  #:use-module (gnu packages package-management)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages groff)
  #:use-module ((guix licenses) #:prefix license:))

(define-public python-toml-0.10
  (package
   (inherit python-toml)
   (version "0.10.0")
   (source (origin
	    (method url-fetch)
	    (uri (pypi-uri "toml" version))
	    (sha256
	     (base32
	      "0p1xww2mzkhqvxkfvmfzm58bbfj812zhdz4rwdjiv94ifz2q37r2"))))))

(define-public python-pyenchant
  (package
   (name "python-pyenchant")
   (version "2.0.0")
   (source (origin
	    (method git-fetch)
	    (uri (git-reference
		  (url "https://github.com/rfk/pyenchant.git")
		  (commit (string-append "v" version))))
	    (file-name (git-file-name name version))
	    (sha256
	     (base32
	      "0a0fcaz6mk7zjgnh9nzg5bl9qvg5ifdbq7l1plb14l060az7b8yx"))))
   (build-system python-build-system)
   (native-inputs
    `(("aspell" ,aspell)
      ("aspell-dict-en" ,aspell-dict-en)))
   (propagated-inputs
    `(("enchant" ,enchant)))
   (arguments
    `(#:phases (modify-phases %standard-phases
                 (add-before 'build 'patch-lib
                   ;; Adjust the library loading routine such that it
                   ;; picks exactly the library that this package was
                   ;; built with (while still allowing user override
                   ;; via the provided PYENCHANT_LIBRARY_PATH
                   ;; environment variables).
                   (lambda* (#:key inputs #:allow-other-keys)
                     (substitute* "enchant/_enchant.py"
                       (("yield.*PYENCHANT_LIBRARY_PATH.*" &)
                        (string-append & "    yield \""
                                       (assoc-ref inputs "enchant")
                                       "/lib/libenchant-2.so\"\n")))
                     #t)))))
   (home-page "https://github.com/rfk/pyenchant.git")
   (synopsis "Python bindings for the Enchant spellchecker")
   (description "This package provides a set of Python language
bindings for the Enchant spellchecking library.")
   (license license:lgpl2.1+)))

(define-public rpmlint
  (let ((commit "5062790b4cd6a998513f7a0223f4f1e264a25c98")
	(revision "0"))
    (package
     (name "rpmlint")
     (version (git-version "1.11" revision commit))
     (source (origin
	      (method git-fetch)
	      (uri (git-reference
		    (url "https://github.com/rpm-software-management/rpmlint.git")
		    (commit commit)))
	      (file-name (git-file-name name version))
	      (sha256
	       (base32
		"12rqpqnxj4shk3ki8p02wrmgn87x0zj6hpjrww534jzy721bi951"))))
     (build-system python-build-system)
     (native-inputs
      `(("aspell" ,aspell)
        ;; TODO: 2 tests still failing, possibly due to differences in the
        ;; dictionary output, i.e. the test is expecting certain output from
        ;; aspell, but our aspell is producing different spelling suggestions.
	("aspell-dict-en" ,aspell-dict-en)
	("perl" ,perl)
	("python-pytest-cov" ,python-pytest-cov)
	("python-pytest-flake8" ,python-pytest-flake8)
	("python-pytest-runner" ,python-pytest-runner)))
     (inputs
      `(("python" ,python)
	("python-file" ,python-file)
	("python-pyxdg" ,python-pyxdg)
	("python-setuptools" ,python-setuptools)
	("python-toml" ,python-toml-0.10)
	("rpm" ,rpm)
	("bzip2" ,bzip2)
	("cpio" ,cpio)
	("gzip" ,gzip)
	("xz" ,xz)
	;; Optional dependencies.  XXX: Maybe move to native-inputs?
	("appstream-glib" ,appstream-glib)
	("desktop-file-utils" ,desktop-file-utils) ; For 'desktop-file-validate'
	("enchant" ,enchant)
	("python-pyenchant" ,python-pyenchant)
	("aspell" ,aspell)
	("groff" ,groff)))
     (home-page "https://github.com/rpm-package-management/rpmlint")
     (synopsis "Check common errors in rpm packages")
     (description "rpmlint is a tool for checking common errors in rpm
packages.  rpmlint can be used to test individual packages before
uploading or to check an entire distribution.  It can check binary
rpms, source rpms, and plain specfiles, but all checks do not apply to
all argument types.  For best check coverage, run rpmlint on source
rpms instead of plain specfiles.")
     (license license:gpl2))))
